    var ws = null;
	var isopened = false;
	var target = 'ws://localhost:9110';
	var opencallback,recvmsgcallback,disconncallback;

	function sendmsg(msg) {
		var b = false;
            if (ws != null) {
                ws.send(msg);
				b = true;
            }
			return b;
        }

	function closeandreset(){
		connect(target);
	}

	function connect() {
            //closecallback = closeandreset;
            if (target == '') {
                //alert('Please input server side connection implementation.');
                return 'Please input server side connection implementation.';
            }

            if ('WebSocket' in window) {
                ws = new WebSocket(target);
            } else if ('MozWebSocket' in window) {
                ws = new MozWebSocket(target);
            } else {
                //alert('WebSocket is not supported by this browser.');
                return 'WebSocket is not supported by this browser.';
            }

            ws.onopen = function () {
                isopened = true;
				if(opencallback != null){
					opencallback(true);
				}
            };

            ws.onmessage = function (event) {
				if(recvmsgcallback != null){
					recvmsgcallback(event.data);
				}
            };

            ws.onclose = function (event) {
				disconnect();
				if(disconncallback != null){
					disconncallback(false);
			    }
				setTimeout(closeandreset,5000);
            };
        }

        function disconnect() {
            if (ws != null) {
                ws.close();
                ws = null;
            }
			
        }

       

       